package cn.tedu.ivos.base.util;

import java.security.SecureRandom;

public class PasswordUtil {
    private static final String AllOWED_CHARS=  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
    private static final SecureRandom random=new SecureRandom();

    public static String generateRandomPassword(int length){
        if(length<5) throw new RuntimeException("密码长度不能小于5");

        StringBuilder password=new StringBuilder();
        for(int i=0;i<length;i++){
            int index=random.nextInt(AllOWED_CHARS.length());
            char randomChar=AllOWED_CHARS.charAt(index);
            password.append(randomChar);
        }
        return password.toString();

    }
}
